<template>
	<view class="files">
		<web-view :src="webViewUrl"></web-view>
<!-- 		<uni-nav-bar dark :fixed="true" :border="false" background-color="#FFFFFF" status-bar 
			title="客户管理" left-icon="left" @clickLeft="toBack" color="#000" />
		<u-sticky offset-top="64">
			<u-subsection :list="list" :current="curNow" @change="sectionChange"></u-subsection>
		</u-sticky>
		<view class="files-body">
			<scroll-view class="clients-scroll-view" :scroll-y="true" 
				@scrolltolower="scrolltolower" v-if="curNow !== 2">
				<view class="clients-row" v-for="(item,index) in clientsList" :key="index"
					@click="toPage('/pages/files/myFiles?id='+item.id)">
					<view style="display: flex;justify-content: space-between;align-items: center;">
						<text style="width: 60%;">{{`姓名：${item.name}`}}</text>
						<u-tag text="成交客户" type="success" plain plainFill size="mini"
							v-if="item.type===0">
						</u-tag>
						<u-tag text="意向客户" type="warning" plain plainFill size="mini"
							v-if="item.type===1">
						</u-tag>
						<u-tag text="潜在客户" plain plainFill size="mini"
							v-if="item.type===2">
						</u-tag>
						<u-tag text="失信客户" type="error" plain plainFill size="mini"
							v-if="item.type===3">
						</u-tag>
					</view>
					<view class="clients-row-text">
						{{`电话：${item.phone}`}}
					</view>
					<view class="clients-row-text">
						{{`公司：${item.company}`}}
					</view>
					<view class="clients-row-text">
						{{`地址：${item.addressShow}`}}
					</view>
					<view class="clients-row-text">
						{{`约谈时间：${formatDate(item.remindTime)}`}}
					</view>
				</view>
			</scroll-view>
		</view> -->
	</view>
</template>

<script>
	import clientApi from '../../request/clientApi';
	import config from "../../request/config.js";
	export default {
		data() {
			return {
				webViewUrl: "",
				path: [],
				list: ['客户列表','公海列表','添加客户'],
				curNow: 0,
				clientsList: [],
				currentPage: 1,
				pageSize: 10,
				notData: false
			}
		},
		onLoad(params) {
			let path = params.path
			console.log("path===>",path)
			let token = uni.getStorageSync("OaAuth")
			let userInfo = uni.getStorageSync("loginUser")
			let baseUrl = config.WEB_VIEW_URL+path
			this.webViewUrl = baseUrl+"?token="+token+"&user="+JSON.stringify(userInfo)
			// this.getClientsList();
		},
		methods: {
			// 返回上个页面
			toBack(){
				uni.navigateBack({
					delta: 1, // 返回的页面数，1表示返回上一页
					animationType: 'pop-out', // 页面关闭的动画效果
					animationDuration: 300, // 页面关闭的动画时间
				});
			},
			toPage(url){
				uni.navigateTo({
					url:url
				})
			},
			// 分段器改变
			sectionChange(index){
				this.curNow = index;
				if (index !== 2){
					this.currentPage = 1;
					this.pageSize = 10;
					this.clientsList = [];
					this.notData = false;
					this.getClientsList();
				}
			},
			// 获取客户列表
			getClientsList(){
				uni.showLoading({
					title: "请求中...",
					mask: true
				})
				const data = {
					currentPage: this.currentPage,
					pageSize: this.pageSize,
					isSalesman: this.curNow
				}
				clientApi.getClientsList(data).then(res =>{
					if (res.code === 200){
						if (res.data.clientsVoList.length === 0){
							this.notData = true;
						}else {
							res.data.clientsVoList.forEach(item =>{
								item.addressShow = item.province+item.city+item.district+item.address
								if (item.content === null){
									item.content = '' 
								}
								this.clientsList.push(item);
							})
						}
					}
				}).finally(() =>{
					uni.hideLoading();
				})
			},
			// 滑动到底部
			scrolltolower(){
				if (this.notData){
					// 没有更多数据了
					this.$tip.tip("没有更多数据了")
				}else {
					this.currentPage++;
					this.getClientsList();
				}
			},
			// 格式化时间
			formatDate(date) {
			  const d = new Date(date);
			  const year = d.getFullYear();
			  const month = (d.getMonth() + 1).toString().padStart(2, "0");
			  const day = d.getDate().toString().padStart(2, "0");
			  const hours = d.getHours().toString().padStart(2, "0");
			  const minutes = d.getMinutes().toString().padStart(2, "0");
			  const seconds = d.getSeconds().toString().padStart(2, "0");
			  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
		}
	}
</script>

<style>
	.files{
		min-height: 100vh;
		background-color: #eeeeef;
	}
	
	.clients-scroll-view{
		height: 81vh;
		padding-bottom: 20rpx;
	}
	
	.clients-row{
		width: 90%;
		height: 350rpx;
		margin: auto;
		margin-top: 20rpx;
		padding: 0 20rpx;
		background-color: #ffffff;
		border-radius: 12rpx;
		line-height: 71rpx;
	}
	
	.clients-row-text{
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>